package org.nf.web.config;

/**
 * @author wangl
 * @date 2023/5/16
 * MVC配置
 */
public class MvcConfig {
    /**
     * 扫描设置
     */
    private Scan scan = new Scan();
    /**
     * 上传设置
     */
    private MultipartConfig multipart = new MultipartConfig();
    /**
     * 字符编码设置
     */
    private CharacterEncodingConfig encoding = new CharacterEncodingConfig();
    /**
     * 跨域配置
     */
    private CorsConfig cors = new CorsConfig();

    public Scan getScan() {
        return scan;
    }

    public void setScan(Scan scan) {
        this.scan = scan;
    }

    public MultipartConfig getMultipart() {
        return multipart;
    }

    public void setMultipart(MultipartConfig multipart) {
        this.multipart = multipart;
    }

    public CharacterEncodingConfig getEncoding() {
        return encoding;
    }

    public void setEncoding(CharacterEncodingConfig encoding) {
        this.encoding = encoding;
    }

    public CorsConfig getCors() {
        return cors;
    }

    public void setCors(CorsConfig cors) {
        this.cors = cors;
    }

    public static class Scan {
        /**
         * 扫描的包名
         */
        private String[] basePackages = {};

        public String[] getBasePackages() {
            return basePackages;
        }

        public void setBasePackages(String[] basePackages) {
            this.basePackages = basePackages;
        }
    }

    public static class CharacterEncodingConfig {
        private boolean enable = false;
        private String charset;
        private boolean force = false;
        private boolean forceRequest = false;
        private boolean forceResponse = false;

        public boolean getEnable() {
            return enable;
        }

        public void setEnable(boolean enable) {
            this.enable = enable;
        }

        public String getCharset() {
            return charset;
        }

        public void setCharset(String charset) {
            this.charset = charset;
        }

        public boolean getForce() {
            return force;
        }

        public void setForce(boolean force) {
            this.force = force;
        }

        public boolean getForceRequest() {
            return forceRequest;
        }

        public void setForceRequest(boolean forceRequest) {
            this.forceRequest = forceRequest;
        }

        public boolean getForceResponse() {
            return forceResponse;
        }

        public void setForceResponse(boolean forceResponse) {
            this.forceResponse = forceResponse;
        }
    }

    public static class MultipartConfig {
        private Boolean enable = false;
        private String location = "";
        private long maxFileSize = -1L;
        private long maxRequestSize = -1L;
        private int fileSizeThreshold = 0;

        public Boolean getEnable() {
            return enable;
        }

        public void setEnable(Boolean enable) {
            this.enable = enable;
        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public long getMaxFileSize() {
            return maxFileSize;
        }

        public void setMaxFileSize(long maxFileSize) {
            this.maxFileSize = maxFileSize;
        }

        public long getMaxRequestSize() {
            return maxRequestSize;
        }

        public void setMaxRequestSize(long maxRequestSize) {
            this.maxRequestSize = maxRequestSize;
        }

        public int getFileSizeThreshold() {
            return fileSizeThreshold;
        }

        public void setFileSizeThreshold(int fileSizeThreshold) {
            this.fileSizeThreshold = fileSizeThreshold;
        }
    }

    public static class CorsConfig {
        private Boolean enable = false;
        private String mapping = "/*";
        private String[] allowedOrigins = {"*"};
        private String[] allowedMethods = {"HEAD", "GET", "POST"};
        private String[] allowedHeaders = {"*"};
        private String[] exposedHeaders = {};
        private Boolean allowCredentials;
        private Long maxAge = 1800L;

        public Boolean getEnable() {
            return enable;
        }

        public void setEnable(Boolean enable) {
            this.enable = enable;
        }

        public String getMapping() {
            return mapping;
        }

        public void setMapping(String mapping) {
            this.mapping = mapping;
        }

        public String[] getAllowedOrigins() {
            return allowedOrigins;
        }

        public void setAllowedOrigins(String[] allowedOrigins) {
            this.allowedOrigins = allowedOrigins;
        }

        public String[] getAllowedMethods() {
            return allowedMethods;
        }

        public void setAllowedMethods(String[] allowedMethods) {
            this.allowedMethods = allowedMethods;
        }

        public String[] getAllowedHeaders() {
            return allowedHeaders;
        }

        public void setAllowedHeaders(String[] allowedHeaders) {
            this.allowedHeaders = allowedHeaders;
        }

        public String[] getExposedHeaders() {
            return exposedHeaders;
        }

        public void setExposedHeaders(String[] exposedHeaders) {
            this.exposedHeaders = exposedHeaders;
        }

        public Boolean getAllowCredentials() {
            return allowCredentials;
        }

        public void setAllowCredentials(Boolean allowCredentials) {
            this.allowCredentials = allowCredentials;
        }

        public Long getMaxAge() {
            return maxAge;
        }

        public void setMaxAge(Long maxAge) {
            this.maxAge = maxAge;
        }
    }
}